package com.sw.small_world.fragment.home.persondoing;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sw.small_world.R;
import com.sw.small_world.activity.ClickButtonActivity;
import com.sw.small_world.adapter.topicsquare.TopicSquareDetailAdapter;
import com.sw.small_world.fragment.base.BaseFragment;
import com.sw.small_world.utils.CommonUtils;
import com.sw.small_world.utils.ConstantUtils;
import com.sw.small_world.utils.PopUtils;
import com.sw.small_world.utils.ToastUtil;
import com.sw.small_world.widgets.CircleImageView;
import com.sw.small_world.widgets.MarkStreamLayout;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/3/21.
 */

public class PersonDoingDetailFragment extends BaseFragment {


    ListView listView;
    RelativeLayout collect;
    RelativeLayout grade;
    RelativeLayout answer;
    @Bind(R.id.iv_portrait)
    CircleImageView ivPortrait;
    @Bind(R.id.tv_name)
    TextView tvName;
    @Bind(R.id.tv_deep)
    TextView tvDeep;
    @Bind(R.id.topic_line1)
    View topicLine1;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_content)
    TextView tvContent;
    @Bind(R.id.tv_time)
    TextView tvTime;
    @Bind(R.id.topic_line2)
    View topicLine2;
    @Bind(R.id.tv_scan_num)
    TextView tvScanNum;
    @Bind(R.id.tv_comment_num)
    TextView tvCommentNum;
    @Bind(R.id.tv_collect_num)
    TextView tvCollectNum;
    @Bind(R.id.ll1)
    LinearLayout ll1;
    @Bind(R.id.mark)
    MarkStreamLayout mark;
    ArrayList<String> markList = new ArrayList<>();
    private ClickButtonActivity activity;
    private ArrayList<String> commentList = new ArrayList<>();

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        activity = (ClickButtonActivity) getActivity();
        setActionBar();
    }

    @Override
    protected Object requestData() {
        for (int i = 0; i < 10; i++) {
            commentList.add("" + i);
        }
        return ConstantUtils.STATE_SUCCESSED;
    }

    @Override
    protected View getSuccessView() {
        View view = View.inflate(activity, R.layout.fragment_person_doing_detail, null);
        listView = (ListView) view.findViewById(R.id.list_view);
        collect = (RelativeLayout) view.findViewById(R.id.collect);
        grade = (RelativeLayout) view.findViewById(R.id.grade);
        answer = (RelativeLayout) view.findViewById(R.id.answer);
        grade.setOnClickListener(this);
        initView();
        return view;
    }

    private void initView() {
        View header = View.inflate(activity, R.layout.header_person_doing_detail, new LinearLayout(activity));
        ButterKnife.bind(this, header);
        listView.addHeaderView(header);
        listView.setAdapter(new TopicSquareDetailAdapter(commentList, activity));
        initMark();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.grade:
                new PopUtils().initGradePop(activity, new PopUtils.OnSureGradeListener() {
                    @Override
                    public void onSure(int grade) {
                        ToastUtil.show("评分为：" + grade);
                    }
                }).showAsDropDown(activity.popView);
                break;
        }
    }
    private void initMark() {
        markList.add("杀猪的");
        markList.add("健康");
        ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.rightMargin = CommonUtils.sp2px(5);
        lp.bottomMargin = CommonUtils.sp2px(5);
        for (int i = 0; i < markList.size(); i++) {
            TextView view = new TextView(getActivity());
            view.setText(markList.get(i));
            view.setTextSize(10);
            view.setTextColor(Color.parseColor("#999999"));
            view.setBackgroundResource(R.drawable.shape_round_grey);
            view.setPadding(CommonUtils.sp2px(10), CommonUtils.sp2px(3),
                    CommonUtils.sp2px(10), CommonUtils.sp2px(3));
            final int finalI = i;
            mark.addView(view, lp);
        }
    }
    private void setActionBar() {
        activity.tvTitle.setText("人脉办事详情");
        activity.tvRight.setVisibility(View.VISIBLE);
        activity.tvRight.setText("举报");
        activity.tvRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.show("举报");
            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
